# -*- coding: utf-8 -*-

import  wx
import  os
import  wx.wizard as wiz

#import  images
import  encodings.mbcs
import  codecs
import GenericTable
import wx.grid
import validator
import wizdata
import wizpages


class NewCol:
    
    def __init__(self, parent, name, i):
        self.sizer = parent.GetSizer()

        self.name = name
        self.dir = 1        
        self.col_type = None
        self.table_ = 'aid_items'
        
        self.cblist =(u'工资项',u'工资项')
        self.tables = ['aid_items', 'aid_items']
        id = wx.NewId()
        txt = wx.StaticText(parent, id, name, size = (120, -1))
        self.sizer.Add(txt,pos=(i, 1))
        
        #self.colsdata[id] = [name,""]
        
        id1 = wx.NewId()
        
        cb = wx.ComboBox(parent, id1, u"", (90, 50), (95, -1), self.cblist, style = wx.CB_DROPDOWN|wx.CB_READONLY, #|wxTE_PROCESS_ENTER
                    validator=validator.CharValidator()
                    )
        
        #self.cols[id1]=id

        self.sizer.Add(cb,pos=(i, 3))          
        parent.Bind(wx.EVT_COMBOBOX, self.OnComboBox, cb)   

        self.direction = [u'增加 ', u'减少']
        self.dirs = [1, -1]
        #sizer = wx.BoxSizer(wx.VERTICAL)

        rb = wx.RadioBox(
                parent, -1, "", wx.DefaultPosition, (120,-1),
                self.direction, 2, wx.RA_SPECIFY_COLS
                )
        self.sizer.Add(rb,pos=(i, 2)) 
        parent.Bind(wx.EVT_RADIOBOX, self.EvtRadioBox, rb)


    def EvtRadioBox(self, event):
        #rb_id = event.GetId()
        rb = event.GetEventObject()
        val = rb.GetSelection()
        self.dir = self.dirs[val]
        event.Skip()
        
    def OnComboBox(self,event):
        cb_id = event.GetId()
        #data = event.GetSelection()
        cb = event.GetEventObject()
        val = cb.GetSelection() #.encode('utf8')
        self.table_ = self.tables[val]
        event.Skip()



class NewColumnsPage(wiz.PyWizardPage):
    def __init__(self, parent, title):
        wiz.PyWizardPage.__init__(self, parent)
        self.next = self.prev = None
        
        self.sizer = wx.GridBagSizer(hgap=5, vgap=5)
        #wizPg.SetSizer(sizer)
        self.data = wizdata.WizData()
        self.title = title
        title = wx.StaticText(self, -1, self.title)
        title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
        self.sizer.Add(title, pos = (0,1),span = (1,4))        
        self.newcols = []
        
        self.cols = {}
        self.colsdata = {}
        self.cbdict = {u'工资表':['tab1','-1'],u'通讯录':['tab2','1']}
        # {u'工资表':['tab1','-1'],u'通讯录':['tab2','1']}
        
        #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnWizPageChanging)
        #self.Build() 

        
        self.SetSizer(self.sizer)        
        self.Fit()
        
    def GetSizer(self):
        return self.sizer
    
    def SetNext(self, next):
        self.next = next
      
    def SetPrev(self, prev):
        self.prev = prev
    
    def GetNext(self):
        next = self.next
        pages = wizpages.WizPages()
        #pages.page6.SetPrev(pages.page5)            
        return pages.page6
            
    def GetPrev(self):
        return self.prev
        
    def __getData(self):
        
        data = wizdata.WizData()
        if len(data.newcol) > 0:
            list = data.newcol
        else:
            list = [u"新类型1",u"新类型2",u"新类型3",u"新类型4",u"新类型5"]
        return list
        
    def GetCol(self):
        return self.newcols
        
    def Build(self):
        self.cols = {}
        self.colsdata = {}
        
        data = wizdata.WizData()

        data.option = 3
        
        list = self.__getData()
        
        self.sizer.Add(wx.StaticText(self, -1, u'新增条目', size = (120, -1)),pos=(1, 1))

        self.sizer.Add(wx.StaticText(self, -1, u'收入/扣除', size = (120, -1)),pos=(1, 2))

        self.sizer.Add(wx.StaticText(self, -1, u'分类', size = (120, -1)),pos=(1, 3))
        
        i = 1
        for x in list:
            i = i+1
            nc = NewCol(self, x , i)
            self.newcols.append( nc )  #
            self.SetSizer(self.sizer)
            self.Fit()
            
        
class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "", size=(800, 660)) 
        wizard = wiz.Wizard(self, -1, u"数据导入向导")
        data = wizdata.WizData()
        data.newcol=('abc','def')
        page1 = NewColumnsPage(wizard, u"创建新项目")
        wizard.FitToPage(page1)
        wizard.RunWizard(page1)

def test():
    app = wx.PySimpleApp()
    TestFrame().Show()
    app.MainLoop() 


if __name__ == "__main__":
    test()
